package cn.dogeye.service.impl;

import cn.dogeye.entity.SysAuth;
import cn.dogeye.dao.SysAuthDao;
import cn.dogeye.service.SysAuthService;
import cn.dogeye.service.SysRoleAuthRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author watson
 * @since 2021-12-03
 */
@Service
public class SysAuthServiceImpl extends ServiceImpl<SysAuthDao, SysAuth> implements SysAuthService {

    @Autowired
    SysRoleAuthRelationService relationService;

    @Override
    public List<SysAuth> getAuth(Integer id) {
        return baseMapper.getAuth(id);
    }

    @Transactional
    @Override
    public void delAuthByIds(List<String> authIds) {
        try {
            HashMap<String,List<String>> map=new HashMap<>();
            map.put("authIds",authIds);
            baseMapper.delAuthByIds(map);
            relationService.delRelByAuthId(authIds);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Transactional
    @Override
    public void addSysAuth(SysAuth sysAuth) {
        try {
            baseMapper.insert(sysAuth);
            relationService.saveAuthId(sysAuth.getSysAuthId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
